home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / rmtlog1a / moderror.bas < prev    next >
BASIC Source File  |  1999-03-21  |  2KB  |  81 lines

  1. Attribute VB_Name = "modErrorHandling"
  2. Option Explicit
  3.  
  4. ' Define your custom errors here.  Be sure to use numbers
  5. ' greater than 512, to avoid conflicts with OLE error numbers.
  6. Public Const MyObjectError1 = 1000
  7. Public Const MyObjectError2 = 1010
  8. Public Const MyObjectErrorN = 1234
  9. Public Const MyUnhandledError = 9999
  10.  
  11. Public Const ERR_SOURCE_DISABLED = 10001
  12. Public Const ERR_LOGDEST_DISABLED = 10002
  13. Public Const ERR_CONNECT_FAILED = 10003
  14. Public Const ERR_NO_LOGDEST = 10004
  15. Public Const ERR_NO_SOURCE = 10005
  16. Public Const ERR_FILEOPEN_FAILED = 10006
  17. Public Const ERR_SOURCE_NULL = 10007
  18. Public Const ERR_LOGDEST_NULL = 10008
  19. Public Const ERR_WRITELOG_DISABLED = 10009
  20. 'Public Const ERR_ = 10010
  21. 'Public Const ERR_ = 10011
  22. 'Public Const ERR_ = 10012
  23. 'Public Const ERR_ = 10013
  24. 'Public Const ERR_ = 10014
  25. 'Public Const ERR_ = 10015
  26. 'Public Const ERR_ = 10016
  27. 'Public Const ERR_ = 10017
  28. 'Public Const ERR_ = 10018
  29. 'Public Const ERR_ = 10019
  30. 'Public Const ERR_ = 10020
  31.  
  32. Private Function GetErrorTextFromResource(ErrorNum As Long) _
  33.           As String
  34.       Dim strMsg As String
  35.       
  36.  
  37.       ' this function will retrieve an error description from a resource
  38.       ' file (.RES).  The ErrorNum is the index of the string
  39.       ' in the resource file.  Called by RaiseError
  40.  
  41.  
  42.       On Error GoTo GetErrorTextFromResourceError
  43.       
  44.  
  45.       ' get the string from a resource file
  46.       GetErrorTextFromResource = LoadResString(ErrorNum)
  47.       
  48.  
  49.       Exit Function
  50.       
  51.  
  52. GetErrorTextFromResourceError:
  53.       
  54.  
  55.       If Err.Number <> 0 Then
  56.             GetErrorTextFromResource = "An unknown error has occurred!"
  57.       End If
  58.       
  59.  
  60. End Function
  61.  
  62.  
  63. Public Sub RaiseError(ErrorNumber As Long, Source As String)
  64.       Dim strErrorText As String
  65.  
  66.  
  67.       'there are a number of methods for retrieving the error
  68.       'message.  The following method uses a resource file to
  69.       'retrieve strings indexed by the error number you are
  70.       'raising.
  71.       strErrorText = GetErrorTextFromResource(ErrorNumber)
  72.  
  73.  
  74.       'raise an error back to the client
  75.       Err.Raise vbObjectError + ErrorNumber, Source, strErrorText
  76.  
  77.  
  78. End Sub
  79.  
  80.  
  81.